﻿using TrueSync;
using Unity.VisualScripting;

namespace HEFramework
{
    public static class RewardSystem
    {
        [EntitySystem]
        public class RewardAwakeSystem : AwakeSystem<Reward>
        {
            protected override void Awake(Reward _self)
            {
            }
        }


        /// <summary>
        /// 团队奖励变动
        /// </summary>
        /// <param name="_self"></param>
        /// <param name="_id"></param>
        /// <param name="_value"></param>
        public static void ChangeTeamReward(this Reward _self, int _id, FP _value)
        {
            var team = _self.GetSceneChild<Team>();
            if (team == null)
            {
                return;
            }


            switch (_id)
            {
                case (int)eReward.G:
                case (int)eReward.G_R:
                case (int)eReward.K:
                case (int)eReward.K_R:
                case (int)eReward.G_S:
                case (int)eReward.K_S:
                case (int)eReward.EXP_S:
                case (int)eReward.ITEM:
                    //针对玩家
                    _self.ChangeReward(null, _id, _value);
                    break;

                default:
                    //针对英雄
                    for (int i = 0; i < team.Heros.Count; i++)
                    {
                        var entity = team.Heros[i].Entity;
                        if (entity == null)
                        {
                            continue;
                        }

                        _self.ChangeReward(entity, _id, _value);
                    }

                    break;
            }
        }

        /// <summary>
        /// 奖励变动
        /// </summary>
        /// <param name="_self"></param>
        /// <param name="_entity"></param>
        /// <param name="_id"></param>
        /// <param name="_value"></param>
        public static void ChangeReward(this Reward _self, Entity _entity, int _id, FP _value)
        {
            Player player = null;
            AttributeComponent ac = null;

            player = _self.GetSceneChild<Player>();
            if (_entity != null)
            {
                ac = _entity.GetChild<AttributeComponent>();
            }

            switch (_id)
            {
                case (int)eReward.G:
                    player?.Change_G(_value);
                    break;
                case (int)eReward.G_R:
                    player?.Change_G_R(_value);
                    break;
                case (int)eReward.K:
                    player?.Change_K(_value);
                    break;
                case (int)eReward.K_R:
                    player?.Change_K_R(_value);
                    break;
                case (int)eReward.EXP:
                    ac?.Change_EXP(_value);
                    break;
                case (int)eReward.EXP_R:
                    ac?.Change_EXP_R(_value);
                    break;
                case (int)eReward.P_ATK:
                    ac?.Change_P_ATK(_value);
                    break;
                case (int)eReward.P_ATK_PCT:
                    ac?.Change_P_ATK_PCT(_value);
                    break;
                case (int)eReward.P_DEF:
                    ac?.Change_P_DEF(_value);
                    break;
                case (int)eReward.P_DEF_PCT:
                    ac?.Change_P_DEF_PCT(_value);
                    break;
                case (int)eReward.M_DEF:
                    ac?.Change_M_DEF(_value);
                    break;
                case (int)eReward.X_HP:
                    ac?.Change_X_HP(_value);
                    break;
                case (int)eReward.X_HP_PCT:
                    ac?.Change_X_HP_PCT(_value);
                    break;
                case (int)eReward.X_MP:
                    ac?.Change_X_MP(_value);
                    break;
                case (int)eReward.X_MP_PCT:
                    ac?.Change_X_MP_PCT(_value);
                    break;
                case (int)eReward.REC_HP:
                    ac?.Change_REC_HP(_value);
                    break;
                case (int)eReward.REC_MP:
                    ac?.Change_REC_MP(_value);
                    break;
                case (int)eReward.P_ATK_SP:
                    ac?.Change_P_ATK_SP(_value);
                    break;
                case (int)eReward.P_ATK_SP_PCT:
                    ac?.Change_P_ATK_SP_PCT(_value);
                    break;
                case (int)eReward.M_ATK_SP:
                    ac?.Change_M_ATK_SP(_value);
                    break;
                case (int)eReward.P_CRT:
                    ac?.Change_P_CRT(_value);
                    break;
                case (int)eReward.M_CRT:
                    ac?.Change_M_CRT(_value);
                    break;
                case (int)eReward.P_CRT_ADD:
                    ac?.Change_P_CRT_ADD(_value);
                    break;
                case (int)eReward.M_CRT_ADD:
                    ac?.Change_M_CRT_ADD(_value);
                    break;
                case (int)eReward.DOG:
                    ac?.Change_DOG(_value);
                    break;
                case (int)eReward.G_S:
                    player?.Change_G_S(_value);
                    break;
                case (int)eReward.K_S:
                    player?.Change_K_S(_value);
                    break;
                case (int)eReward.EXP_S:
                    player?.Change_EXP_S(_value);
                    break;
                case (int)eReward.M_ATK:
                    ac?.Change_M_ATK(_value);
                    break;
                case (int)eReward.M_ATK_PCT:
                    ac?.Change_M_ATK_PCT(_value);
                    break;
                case (int)eReward.LV:
                    ac?.Change_LV((int)_value);
                    break;
                case (int)eReward.RANK:
                    ac?.Change_RANK((int)_value);
                    break;
                case (int)eReward.G_PCT:
                    player?.Change_G(player.G * Formula.PCT(_value));
                    break;
                case (int)eReward.K_PCT:
                    player?.Change_K(player.K * Formula.PCT(_value));
                    break;
                case (int)eReward.REC_HP_PCT:
                    ac?.Change_REC_HP_PCT(_value);
                    break;
                case (int)eReward.REC_MP_PCT:
                    ac?.Change_REC_MP_PCT(_value);
                    break;
                case (int)eReward.HP:
                    ac?.Change_HP(_value);
                    break;
                case (int)eReward.MP:
                    ac?.Change_MP(_value);
                    break;
                case (int)eReward.HP_PCT:
                    ac?.Change_HP(ac.X_HP.Value * Formula.PCT(_value));
                    break;
                case (int)eReward.MP_PCT:
                    ac?.Change_MP(ac.X_MP.Value * Formula.PCT(_value));
                    break;
                case (int)eReward.P_VP:
                    ac?.Change_P_VP(_value);
                    break;
                case (int)eReward.M_VP:
                    ac?.Change_M_VP(_value);
                    break;
                case (int)eReward.TRT:
                    ac?.Change_TRT(_value);
                    break;
                case (int)eReward.ITEM:
                    break;
            }
        }
    }
}